package wechat;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.alibaba.fastjson.JSON;
import com.mhuang.module.wechat.config.WechatConfig;
import com.mhuang.module.wechat.service.WechatConfigService;
import com.mhuang.wechat.common.model.menu.Button;
import com.mhuang.wechat.common.model.menu.Menu;

/**
 * 
 * @Package: wechat
 * @Description 创建菜单
 * @author huang.miao
 * @date 2017年2月8日 下午4:15:45  
 * @since 1.0.0
 * @group skiper-opensource
 */
@RunWith(SpringJUnit4ClassRunner.class)  
@ContextConfiguration(locations = { "classpath*:spring.xml" })  
public class CreateMenu {

	@Autowired
	private WechatConfig wechatConfig;
	@Autowired
	private WechatConfigService wechatConfigService;
	@Test
	public void test() {
		Menu menu = new  Menu();
		
		//二级菜单创建
		Button button = menu.buttonAddSub("官网", "view", "我的", wechatConfig.getWechat_oauth_getcode_url().replace("REDIRECT_URL","http://你的ip地址"));
		button.addSubButton("view", "联系方式", "http://www.baidu.com");
		menu.getButton().add(button);
		
		//二级菜单创建
		Button button2 = menu.buttonAddSub("我的", "view", "你的", wechatConfig.getWechat_oauth_getcode_url().replace("REDIRECT_URL","http://你的ip地址"));
		button2.addSubButton("view", "网上报名",  wechatConfig.getWechat_oauth_getcode_url().replace("REDIRECT_URL","http://www.baidu.com"));
		menu.getButton().add(button2);
		
		//单个菜单
		menu.buttonAdd("view", "我的", "http://www.baidu.com");
		
		System.out.println(JSON.toJSONString(menu));
		//推送
//		fail(NetWorkUtils.sync(wechatConfig.getWechat_create_menu_url().replace("ACCESS_TOKEN",wechatConfigService.getToken()),JSON.toJSONString(menu)));
	}
}
